<?php
require_once('lzu_op_fns.php');
require_once('merchant_fns.php');
if (session_status() == PHP_SESSION_NONE) {
    session_start();
}
do_html_header('申请店铺');
if (check_have_merchant()) {
    echo '<p>您已经申请开店，请等待审核！</p>';
    echo '<a href="user_center.php">返回用户中心</a>';
    exit;
}
if (isset($_POST['name']) && isset($_POST['intro']) && isset($_POST['address']) && isset($_POST['tel'])) {
    $name = $_POST['name'];
    $intro = $_POST['intro'];
    $tel = $_POST['tel'];
    $address = $_POST['address'];
    $user_id = $_SESSION['uid'];
    $result = apply_merchant($user_id, $name, $intro, $address, $tel);
    if ($result) {
        echo '<p>申请成功！</p>';
    } else {
        echo '<p>申请失败！</p>';
    }
} else {
?>
    <form method="post" action="">
        店铺名: <input type="text" name="name" /><br>
        简&emsp;介: <input type="text" name="intro" /><br>
        电&emsp;话: <input type="text" name="tel" /><br>
        地&emsp;址: <input type="text" name="address" /><br>
        <input type="submit" value="申请" />
    </form>
<?php
}
?>
<a href="user_center.php">返回用户中心</a>